<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
  <link rel="stylesheet" href="/layui/css/layui.css">
  <script src="/layui/layui.js"></script>
</head>
<body>
<blockquote class="layui-elem-quote layui-text">
  <h2>修改学生信息</h2>
</blockquote>
<form class="layui-form" action="">
  <div class="layui-form-item">
    <label class="layui-form-label">学号</label>
    <div class="layui-input-block">
      <input type="text" name="studNo" lay-verify="studNo" autocomplete="off" class="layui-input" id="studNo" readonly>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">姓名</label>
    <div class="layui-input-block">
      <input type="text" name="studName" lay-verify="studName" autocomplete="off" placeholder="请输入学生姓名"
             class="layui-input" id="studName">
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">性别</label>
    <div class="layui-input-block">
      <input type="text" name="sex" lay-verify="sex" autocomplete="off" placeholder="请输入性别"
             class="layui-input" id="sex">
    </div>
  </div>


  <div class="layui-form-item">
    <label class="layui-form-label">民族</label>
    <div class="layui-input-block">
      <input type="text" name="nation" lay-verify="nation" autocomplete="off" placeholder="请输入民族"
             class="layui-input" id="nation">
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">精神面貌</label>
    <div class="layui-input-block">
      <input type="text" name="political" lay-verify="political" autocomplete="off" placeholder="请输入精神面貌"
             class="layui-input" id="political">
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">生日</label>
    <div class="layui-input-block">
      <input type="text" name="birthday" lay-verify="birthday" autocomplete="off" placeholder="请输入生日"
             class="layui-input" id="birthday">
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">学院</label>
    <div class="layui-input-block">
      <input type="text" name="school" lay-verify="school" autocomplete="off" placeholder="请输入学院"
             class="layui-input" id="school">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">专业</label>
    <div class="layui-input-block">
      <input type="text" name="major" lay-verify="major" autocomplete="off" placeholder="请输入专业"
             class="layui-input" id="major">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">入学日期</label>
    <div class="layui-input-block">
      <input type="text" name="entranceTime" lay-verify="entranceTime" autocomplete="off" placeholder="请输入入学日期"
             class="layui-input" id="entranceTime">
    </div>
  </div>



  <div class="layui-form-item">
    <div class="layui-input-block">
      <button type="submit" class="layui-btn" lay-submit="" lay-filter="edit">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>
<script>

  layui.use(['form', 'layer', 'jquery'], function () {
    $ = layui.jquery;
    var form = layui.form,
            layer = layui.layer,
            layedit = layui.layedit,
            laydate = layui.laydate;
    var parent_json = eval('(' + parent.json + ')');

    //执行一个laydate实例
    laydate.render({
      elem: '#entranceTime,#birthday' //指定元素
    });

    $("input[name='studNo']").val(parent_json.studNo);
    $("input[name='studName']").val(parent_json.studName);
    $("input[name='sex']").val(parent_json.sex);
    $("input[name='nation']").val(parent_json.nation);
    $("input[name='political']").val(parent_json.political);
    $("input[name='birthday']").val(parent_json.birthday);
    $("input[name='school']").val(parent_json.school);
    $("input[name='major']").val(parent_json.major);
    $("input[name='entranceTime']").val(parent_json.entranceTime);

    form.render();//刷新
    //自定义验证规则
    form.verify({
      sex: function (value) {
        if (value.length > 1) {
          return '性别格式错误';
        }
      }

    });
    //监听提交
    form.on('submit(edit)', function (data) {
      //获取文本框的值
      var studNo = $("#studNo").val();
      var studName = $("#studName").val();
      var sex = $("#sex").val();
      var nation = $("#nation").val();
      var political = $("#political").val();
      var birthday = $("#birthday").val();
      var school = $("#school").val();
      var major = $("#major").val();
      var entranceTime = $("#entranceTime").val();

      console.log(birthday.length)

      $.ajax({
        type: 'put',
        url: '/editStudent',
        async: true,
        datatype: "json",
        data: {
          studNo: studNo,
          studName: studName,
          sex: sex,
          nation: nation,
          political: political,
          birthday: birthday,
          school: school,
          major: major,
          entranceTime: entranceTime,
        },
        success: function (data) {
          layer.alert('修改成功', {icon: 6, title: '提示', time: 1500})
          setTimeout(function () {
            window.parent.location.reload();
            // window.location.href="index.html";
          }, 1500);
        },
        error: function () {
          layer.alert('请求失败，系统错误', {icon: 7, title: '提示', time: 1000})
        }

      });
      return false;
    });
  });
</script>
</body>
</html>
